<template>
  <div class="details">
    <div class="header" v-for="item in detailsList" :key="item.product_id">
      <div class="title">
        <p class="sp">{{ item.product_name }}</p>
        <div class="list">
          <ul>
            <li>概述</li>
            <li>参数</li>
            <li>用户评价</li>
          </ul>
        </div>
      </div>
    </div>
    <div class="mains">
      <div class="block">
        <el-carousel height="560px">
          <el-carousel-item v-for="item in bannerList" :key="item.id">
            <img :src="'api' + item.product_picture" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="content" v-for="item in detailsList" :key="item.product_id">
        <h1 class="name">{{ item.product_name }}</h1>
        <p class="intro">{{ item.product_intro }}</p>
        <p class="store">小米自营</p>
        <div class="price">
          <span>{{ item.product_selling_price }}元</span>
          <span
            class="del"
            v-if="item.product_selling_price != item.product_price"
            >{{ item.product_price }}元</span
          >
        </div>
        <div class="pro_list">
          <span class="pro_name">{{ item.product_name }}</span>
          <span class="pro_pirce">
            <span></span>
            <span class="pro_del"></span>
          </span>
          <p class="price_num">总计:{{ item.product_price }}元</p>
        </div>
        <div class="button">
          <el-button
            type="danger"
            class="shopcar"
            @click="shopping(item.product_id)"
            >加入购物车</el-button
          >
          <el-button
            type="danger"
            class="like"
            @click="collect(item.product_id)"
            >喜欢</el-button
          >
        </div>
        <div class="pro_policy">
          <ul>
            <li><i class="el-icon-circle-check"></i>小米自营</li>
            <li><i class="el-icon-circle-check"></i>小米发货</li>
            <li><i class="el-icon-circle-check"></i>7天无理由退货</li>
            <li><i class="el-icon-circle-check"></i>7天价格保护</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Shop from "../miAPI/shopping";
import collect from "../miAPI/getCollect";
import Details from "../miAPI/getDetails";
export default {
  data() {
    return {
      detailsList: [],
      bannerList: [],
    };
  },
  activated() {
    var id = this.$route.query.id;
    // console.log("参数" + id);
    this.getDetails(id);
    this.getDetailsPic(id);
  },
  methods: {
    async getDetails(id) {
      // console.log(id)
      let { data: res } = await Details.getDetails({ productID: id });
      // console.log(res);
      this.detailsList = res.Product;
    },
    async getDetailsPic(id) {
      let { data: res } = await Details.getDetailsPic({ productID: id });
      // console.log(res)
      this.bannerList = res.ProductPicture;
    },
    collect(id) {
      if (this.$store.state.user == null) {
        this.$store.commit("setlogin");
        return;
      }
      collect
        .addCollect({ user_id: this.$store.state.user.user_id, product_id: id })
        .then((k) => {
          // console.log(k);
          if (k.data.code == "001") {
            this.$notify({
              type: "success",
              title: "成功",
              message: k.data.msg,
              duration: 3000,
            });
          } else if (k.data.code == "003") {
            this.$notify({
              type: "warning",
              title: "提示",
              message: k.data.msg,
              duration: 3000,
            });
          }
        });
    },
    shopping(id) {
      if (this.$store.state.user == null) {
        this.$store.commit("setlogin");
        return;
      }
      Shop.addShoppingCart({
        user_id: this.$store.state.user.user_id,
        product_id: id,
      }).then((k) => {
        // console.log(k);
        if(k.data.code=="001"){
          this.$notify({
              type: "success",
              title: "成功",
              message: k.data.msg,
              duration: 3000,
            });
        }else if(k.data.code=='002'){
          this.$notify({
            type: "warning",
            title: "提示",
            message: k.data.msg,
            duration: 3000,
          });
        }
      });
    },
  },
};
</script>


<style scoped>
.details {
  min-height: 300px;
}
.header {
  height: 64px;
  margin-top: -20px;
  z-index: 4;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  -webkit-box-shadow: 0 5px 5px rgb(0 0 0 / 7%);
  box-shadow: 0 5px 5px rgb(0 0 0 / 7%);
}
img {
  height: 560px;
  width: 560px;
}
.title {
  width: 1225px;
  height: 64px;
  line-height: 64px;
  font-size: 18px;
  font-weight: 400;
  color: #212121;
  margin: 0 auto;
}
.sp {
  float: left;
  margin-left: 8%;
}
.list {
  height: 64px;
  float: right;
}
.list ul li {
  margin-left: 20px;
  float: left;
  font-size: 14px;
  color: #616161;
}
.mains {
  width: 1225px;
  height: 560px;
  padding-top: 30px;
  margin: 0 auto;
}
.block {
  float: left;
  width: 500px;
  height: 560px;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.content {
  float: left;
  margin-left: 25px;
  width: 640px;
}
.name {
  height: 30px;
  line-height: 30px;
  font-size: 24px;
  font-weight: 400;
  color: #212121;
}
.intro {
  color: #b0b0b0;
  padding-top: 10px;
}
.store {
  color: #ff6700;
  padding-top: 10px;
}
.price {
  display: block;
  font-size: 18px;
  color: #ff6700;
  border-bottom: 1px solid #e0e0e0;
  padding: 25px 0 25px;
}
.del {
  font-size: 14px;
  margin-left: 10px;
  color: #b0b0b0;
  text-decoration: line-through;
}
.pro_list {
  background: #f9f9fa;
  padding: 30px 60px;
  margin: 50px 0 50px;
}
.pro_list span {
  line-height: 30px;
  color: #616161;
}
.pro_pirce {
  float: right;
}
.pro_del {
  margin-left: 10px;
  text-decoration: line-through;
}
.price_num {
  color: #ff6700;
  font-size: 24px;
  padding-top: 20px;
}
.button {
  height: 55px;
  margin: 10px 0 20px 0;
}
.shopcar {
  width: 340px;
  background-color: #ff6700;
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}
.like {
  width: 260px;
  margin-left: 40px;
  background-color: #b0b0b0;
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}
.pro_policy ul li {
  float: left;
  margin-right: 20px;
  color: #b0b0b0;
}
</style>
